/**
 * Candidate number: 35834
 */
package tv.starfu.sequencer.components;

import com.artemis.Component;
import net.beadsproject.beads.core.AudioContext;
import net.beadsproject.beads.ugens.Envelope;

public class AmpEnvelope extends Component {
    private int attack_ms;
    private int decay_ms;
    private int sustain_ms;
    private int release_ms;
    
    private float startVal;
    private float maxVal;
    private float susVal;
    private float endVal;
    
    private AudioContext ac;
    
    private Envelope envelope;

    public AmpEnvelope() {
        
        attack_ms  = 0;
        decay_ms   = 300;
        sustain_ms = 20;
        release_ms = 10;
        
        startVal   = 1;
        maxVal     = 1;
        susVal     = 1;
        endVal     = 1;        
    }
    
    public AmpEnvelope(int[] ADSR, float[] startMaxSusEndValues, AudioContext ac) {
        this.ac = ac;
        attack_ms  = ADSR[0];
        decay_ms   = ADSR[1];
        sustain_ms = ADSR[2];
        release_ms = ADSR[3];
        
        startVal   = startMaxSusEndValues[0];
        maxVal     = startMaxSusEndValues[1];
        susVal     = startMaxSusEndValues[2];
        endVal     = startMaxSusEndValues[3];
        
        createEnvelope();
    }

    public final void createEnvelope() {
        Envelope e = new Envelope(ac,startVal);
        e.addSegment(maxVal, attack_ms);
        e.addSegment(susVal, decay_ms);
        e.addSegment(susVal, sustain_ms);
        e.addSegment(endVal, release_ms, 0.7f);
        this.envelope = e;
    }

    public AudioContext getAc() {
        return ac;
    }

    public void setAc(AudioContext ac) {
        this.ac = ac;
    }

    public int getAttack_ms() {
        return attack_ms;
    }

    public void setAttack_ms(int attack_ms) {
        this.attack_ms = attack_ms;
        createEnvelope();
    }

    public int getDecay_ms() {
        return decay_ms;
    }

    public void setDecay_ms(int decay_ms) {
        this.decay_ms = decay_ms;
        createEnvelope();
    }

    public float getEndVal() {
        return endVal;
    }

    public void setEndVal(float endVal) {
        this.endVal = endVal;
    }

    public Envelope getEnvelope() {
        return envelope;
    }

    public void setEnvelope(Envelope envelope) {
        this.envelope = envelope;
    }

    public float getMaxVal() {
        return maxVal;
    }

    public void setMaxVal(float maxVal) {
        this.maxVal = maxVal;
        createEnvelope();
    }

    public int getRelease_ms() {
        return release_ms;
    }

    public void setRelease_ms(int release_ms) {
        this.release_ms = release_ms;
        createEnvelope();
    }

    public float getStartVal() {
        return startVal;
    }

    public void setStartVal(float startVal) {
        this.startVal = startVal;
        createEnvelope();
    }

    public float getSusVal() {
        return susVal;
    }

    public void setSusVal(float susVal) {
        this.susVal = susVal;
        createEnvelope();
    }

    public int getSustain_ms() {
        return sustain_ms;
    }

    public void setSustain_ms(int sustain_ms) {
        this.sustain_ms = sustain_ms;
        createEnvelope();
    }
    
    
    
}
